<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 6.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css" integrity="sha256-xejo6yLi6vGtAjcMIsY8BHdKsLg7QynVlFMzdQgUuy8=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"gitee.com","root":"/blog/","images":"/blog/images","scheme":"Gemini","darkmode":true,"version":"8.12.3","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}}</script><script src="/blog/js/config.js"></script>

    <meta name="description" content="来自：唐尤华 译自：https:&#x2F;&#x2F;bloggceasy.files.wordpress.com&#x2F;2015&#x2F;05&#x2F;outofmemoryerror2.pdf  1. Java 堆空间发生频率5颗星 造成原因 无法在 Java 堆中分配对象 吞吐量增加 应用程序无意中保存了对象引用，对象无法被 GC 回收 应用程序过度使用 finalizer。finalizer 对象不能被 GC 立刻回收。fin">
<meta property="og:type" content="article">
<meta property="og:title" content="一文了解 OutOfMemory 及解决方案">
<meta property="og:url" content="https://gitee.com/lliugh/blog/2019/02/13/%E4%B8%80%E6%96%87%E4%BA%86%E8%A7%A3%20OutOfMemory%20%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/index.html">
<meta property="og:site_name" content="lliugh 的博客">
<meta property="og:description" content="来自：唐尤华 译自：https:&#x2F;&#x2F;bloggceasy.files.wordpress.com&#x2F;2015&#x2F;05&#x2F;outofmemoryerror2.pdf  1. Java 堆空间发生频率5颗星 造成原因 无法在 Java 堆中分配对象 吞吐量增加 应用程序无意中保存了对象引用，对象无法被 GC 回收 应用程序过度使用 finalizer。finalizer 对象不能被 GC 立刻回收。fin">
<meta property="og:locale">
<meta property="article:published_time" content="2019-02-13T03:09:08.000Z">
<meta property="article:modified_time" content="2019-02-13T03:33:21.000Z">
<meta property="article:author" content="lliugh">
<meta property="article:tag" content="工作">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://gitee.com/lliugh/blog/2019/02/13/%E4%B8%80%E6%96%87%E4%BA%86%E8%A7%A3%20OutOfMemory%20%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-Hans","comments":true,"permalink":"https://gitee.com/lliugh/blog/2019/02/13/%E4%B8%80%E6%96%87%E4%BA%86%E8%A7%A3%20OutOfMemory%20%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/","path":"2019/02/13/一文了解 OutOfMemory 及解决方案/","title":"一文了解 OutOfMemory 及解决方案"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>一文了解 OutOfMemory 及解决方案 | lliugh 的博客</title>
  






  <noscript>
    <link rel="stylesheet" href="/blog/css/noscript.css">
  </noscript>
<link rel="alternate" href="/blog/atom.xml" title="lliugh 的博客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">lliugh 的博客</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li><li class="menu-item menu-item-tags"><a href="/blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a></li><li class="menu-item menu-item-archives"><a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-Java-%E5%A0%86%E7%A9%BA%E9%97%B4"><span class="nav-number">1.</span> <span class="nav-text">1. Java 堆空间</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E7%94%9F%E9%A2%91%E7%8E%87"><span class="nav-number">1.1.</span> <span class="nav-text">发生频率</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%A0%E6%88%90%E5%8E%9F%E5%9B%A0"><span class="nav-number">1.2.</span> <span class="nav-text">造成原因</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88"><span class="nav-number">1.3.</span> <span class="nav-text">解决方案</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-GC-%E5%BC%80%E9%94%80%E8%B6%85%E8%BF%87%E9%99%90%E5%88%B6"><span class="nav-number">2.</span> <span class="nav-text">2. GC 开销超过限制</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E7%94%9F%E9%A2%91%E7%8E%87-1"><span class="nav-number">2.1.</span> <span class="nav-text">发生频率</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%A0%E6%88%90%E5%8E%9F%E5%9B%A0-1"><span class="nav-number">2.2.</span> <span class="nav-text">造成原因</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-1"><span class="nav-number">2.3.</span> <span class="nav-text">解决方案</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-%E8%AF%B7%E6%B1%82%E7%9A%84%E6%95%B0%E7%BB%84%E5%A4%A7%E5%B0%8F%E8%B6%85%E8%BF%87%E8%99%9A%E6%8B%9F%E6%9C%BA%E9%99%90%E5%88%B6"><span class="nav-number">3.</span> <span class="nav-text">3. 请求的数组大小超过虚拟机限制</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E7%94%9F%E9%A2%91%E7%8E%87-2"><span class="nav-number">3.1.</span> <span class="nav-text">发生频率</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%A0%E6%88%90%E5%8E%9F%E5%9B%A0-2"><span class="nav-number">3.2.</span> <span class="nav-text">造成原因</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-2"><span class="nav-number">3.3.</span> <span class="nav-text">解决方案</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-Permgen-%E7%A9%BA%E9%97%B4"><span class="nav-number">4.</span> <span class="nav-text">4. Permgen 空间</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E7%94%9F%E9%A2%91%E7%8E%87-3"><span class="nav-number">4.1.</span> <span class="nav-text">发生频率</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%A0%E6%88%90%E5%8E%9F%E5%9B%A0-3"><span class="nav-number">4.2.</span> <span class="nav-text">造成原因</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-3"><span class="nav-number">4.3.</span> <span class="nav-text">解决方案</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-Metaspace"><span class="nav-number">5.</span> <span class="nav-text">5. Metaspace</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E7%94%9F%E9%A2%91%E7%8E%87-4"><span class="nav-number">5.1.</span> <span class="nav-text">发生频率</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%A0%E6%88%90%E5%8E%9F%E5%9B%A0-4"><span class="nav-number">5.2.</span> <span class="nav-text">造成原因</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-4"><span class="nav-number">5.3.</span> <span class="nav-text">解决方案</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-%E6%97%A0%E6%B3%95%E6%96%B0%E5%BB%BA%E6%9C%AC%E6%9C%BA%E7%BA%BF%E7%A8%8B"><span class="nav-number">6.</span> <span class="nav-text">6. 无法新建本机线程</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E7%94%9F%E9%A2%91%E7%8E%87-5"><span class="nav-number">6.1.</span> <span class="nav-text">发生频率</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%A0%E6%88%90%E5%8E%9F%E5%9B%A0-5"><span class="nav-number">6.2.</span> <span class="nav-text">造成原因</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-5"><span class="nav-number">6.3.</span> <span class="nav-text">解决方案</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-%E6%9D%80%E6%AD%BB%E8%BF%9B%E7%A8%8B%E6%88%96%E5%AD%90%E8%BF%9B%E7%A8%8B"><span class="nav-number">7.</span> <span class="nav-text">7. 杀死进程或子进程</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E7%94%9F%E9%A2%91%E7%8E%87-6"><span class="nav-number">7.1.</span> <span class="nav-text">发生频率</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%A0%E6%88%90%E5%8E%9F%E5%9B%A0-6"><span class="nav-number">7.2.</span> <span class="nav-text">造成原因</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-6"><span class="nav-number">7.3.</span> <span class="nav-text">解决方案</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-%E5%8F%91%E7%94%9F-stack-trace-with-native-method"><span class="nav-number">8.</span> <span class="nav-text">8. 发生 stack_trace_with_native_method</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E7%94%9F%E9%A2%91%E7%8E%87-7"><span class="nav-number">8.1.</span> <span class="nav-text">发生频率</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%A0%E6%88%90%E5%8E%9F%E5%9B%A0-7"><span class="nav-number">8.2.</span> <span class="nav-text">造成原因</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-7"><span class="nav-number">8.3.</span> <span class="nav-text">解决方案</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">lliugh</p>
  <div class="site-description" itemprop="description">一只特立独行的猪</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/blog/archives/">
          <span class="site-state-item-count">17</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/blog/tags/">
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/lliugh" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lliugh" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:guohaoliu@gmail.com" title="E-Mail → mailto:guohaoliu@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/lliugh" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;lliugh" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://twitter.com/lliugh" title="Twitter → https:&#x2F;&#x2F;twitter.com&#x2F;lliugh" rel="noopener" target="_blank"><i class="fab fa-twitter fa-fw"></i>Twitter</a>
      </span>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="Back to top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/lliugh/blog/2019/02/13/%E4%B8%80%E6%96%87%E4%BA%86%E8%A7%A3%20OutOfMemory%20%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="lliugh">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="lliugh 的博客">
      <meta itemprop="description" content="一只特立独行的猪">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="一文了解 OutOfMemory 及解决方案 | lliugh 的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          一文了解 OutOfMemory 及解决方案
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>
      

      <time title="Created: 2019-02-13 11:09:08 / Modified: 11:33:21" itemprop="dateCreated datePublished" datetime="2019-02-13T11:09:08+08:00">2019-02-13</time>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <blockquote>
<p>来自：唐尤华</p>
<p>译自：<a target="_blank" rel="noopener" href="https://bloggceasy.files.wordpress.com/2015/05/outofmemoryerror2.pdf">https://bloggceasy.files.wordpress.com/2015/05/outofmemoryerror2.pdf</a></p>
</blockquote>
<h3 id="1-Java-堆空间"><a href="#1-Java-堆空间" class="headerlink" title="1. Java 堆空间"></a>1. Java 堆空间</h3><h4 id="发生频率"><a href="#发生频率" class="headerlink" title="发生频率"></a>发生频率</h4><p>5颗星</p>
<h4 id="造成原因"><a href="#造成原因" class="headerlink" title="造成原因"></a>造成原因</h4><ol>
<li>无法在 Java 堆中分配对象</li>
<li>吞吐量增加</li>
<li>应用程序无意中保存了对象引用，对象无法被 GC 回收</li>
<li>应用程序过度使用 finalizer。finalizer 对象不能被 GC 立刻回收。finalizer 由结束队列服务的守护线程调用，有时 finalizer 线程的处理能力无法跟上结束队列的增长</li>
</ol>
<h4 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h4><blockquote>
<p>单位对应：GB -&gt; G, g；MB -&gt; M, m；KB -&gt; K, k</p>
</blockquote>
<ol>
<li>使用 -Xmx 增加堆大小</li>
<li>修复应用程序中的内存泄漏</li>
</ol>
<h3 id="2-GC-开销超过限制"><a href="#2-GC-开销超过限制" class="headerlink" title="2. GC 开销超过限制"></a>2. GC 开销超过限制</h3><h4 id="发生频率-1"><a href="#发生频率-1" class="headerlink" title="发生频率"></a>发生频率</h4><p>5颗星</p>
<h4 id="造成原因-1"><a href="#造成原因-1" class="headerlink" title="造成原因"></a>造成原因</h4><ol>
<li>Java 进程98%的时间在进行垃圾回收，恢复了不到2%的堆空间，最后连续5个（编译时常量）垃圾回收一直如此。</li>
</ol>
<h4 id="解决方案-1"><a href="#解决方案-1" class="headerlink" title="解决方案"></a>解决方案</h4><ol>
<li>使用 -Xmx 增加堆大小</li>
<li>使用 -XX:-UseGCOverheadLimit 取消 GC 开销限制</li>
<li>修复应用程序中的内存泄漏</li>
</ol>
<h3 id="3-请求的数组大小超过虚拟机限制"><a href="#3-请求的数组大小超过虚拟机限制" class="headerlink" title="3. 请求的数组大小超过虚拟机限制"></a>3. 请求的数组大小超过虚拟机限制</h3><h4 id="发生频率-2"><a href="#发生频率-2" class="headerlink" title="发生频率"></a>发生频率</h4><p>2颗星</p>
<h4 id="造成原因-2"><a href="#造成原因-2" class="headerlink" title="造成原因"></a>造成原因</h4><ol>
<li>应用程序试图分配一个超过堆大小的数组</li>
</ol>
<h4 id="解决方案-2"><a href="#解决方案-2" class="headerlink" title="解决方案"></a>解决方案</h4><ol>
<li>使用 -Xmx 增加堆大小</li>
<li>修复应用程序中分配巨大数组的 bug</li>
</ol>
<h3 id="4-Permgen-空间"><a href="#4-Permgen-空间" class="headerlink" title="4. Permgen 空间"></a>4. Permgen 空间</h3><h4 id="发生频率-3"><a href="#发生频率-3" class="headerlink" title="发生频率"></a>发生频率</h4><p>3颗星</p>
<h4 id="造成原因-3"><a href="#造成原因-3" class="headerlink" title="造成原因"></a>造成原因</h4><ol>
<li>Permgen 空间包含：<ul>
<li>类的名字、字段、方法</li>
<li>与类相关的对象数组和类型数组</li>
<li>JIT 编译器优化</li>
</ul>
</li>
<li>当 Permgen 空间用尽时，将抛出异常。</li>
</ol>
<h4 id="解决方案-3"><a href="#解决方案-3" class="headerlink" title="解决方案"></a>解决方案</h4><ol>
<li>使用 -XX: MaxPermSize 增加 Permgen 大小</li>
<li>不重启应用部署应用程序可能会导致此问题。重启 JVM 解决</li>
</ol>
<h3 id="5-Metaspace"><a href="#5-Metaspace" class="headerlink" title="5. Metaspace"></a>5. Metaspace</h3><h4 id="发生频率-4"><a href="#发生频率-4" class="headerlink" title="发生频率"></a>发生频率</h4><p>3颗星</p>
<h4 id="造成原因-4"><a href="#造成原因-4" class="headerlink" title="造成原因"></a>造成原因</h4><ol>
<li>从 Java 8 开始 Permgen 改成了 Metaspace，在本机内存中分配 class 元数据（称为 metaspace）。如果 metaspace 耗尽，则抛出异常</li>
</ol>
<h4 id="解决方案-4"><a href="#解决方案-4" class="headerlink" title="解决方案"></a>解决方案</h4><ol>
<li>通过命令行设置 -XX: MaxMetaSpaceSize 增加 metaspace 大小</li>
<li>取消 -XX: maxmetsspacedize</li>
<li>减小 Java 堆大小,为 MetaSpace 提供更多的可用空间</li>
<li>为服务器分配更多的内存</li>
<li>可能是应用程序 bug，修复 bug</li>
</ol>
<h3 id="6-无法新建本机线程"><a href="#6-无法新建本机线程" class="headerlink" title="6. 无法新建本机线程"></a>6. 无法新建本机线程</h3><h4 id="发生频率-5"><a href="#发生频率-5" class="headerlink" title="发生频率"></a>发生频率</h4><p>5颗星</p>
<h4 id="造成原因-5"><a href="#造成原因-5" class="headerlink" title="造成原因"></a>造成原因</h4><ol>
<li>内存不足，无法创建新线程。由于线程在本机内存中创建，报告这个错误表明本机内存空间不足</li>
</ol>
<h4 id="解决方案-5"><a href="#解决方案-5" class="headerlink" title="解决方案"></a>解决方案</h4><ol>
<li>为机器分配更多的内存</li>
<li>减少 Java 堆空间</li>
<li>修复应用程序中的线程泄漏。</li>
<li>增加操作系统级别的限制<ul>
<li>ulimit -a</li>
<li>用户进程数增大 (-u) 1800</li>
</ul>
</li>
<li>使用 -Xss 减小线程堆栈大小</li>
</ol>
<h3 id="7-杀死进程或子进程"><a href="#7-杀死进程或子进程" class="headerlink" title="7. 杀死进程或子进程"></a>7. 杀死进程或子进程</h3><h4 id="发生频率-6"><a href="#发生频率-6" class="headerlink" title="发生频率"></a>发生频率</h4><p>1颗星</p>
<h4 id="造成原因-6"><a href="#造成原因-6" class="headerlink" title="造成原因"></a>造成原因</h4><ol>
<li>内核任务：内存不足结束器，在可用内存极低的情况下会杀死进程</li>
</ol>
<h4 id="解决方案-6"><a href="#解决方案-6" class="headerlink" title="解决方案"></a>解决方案</h4><ol>
<li>将进程迁移到不同的机器上</li>
<li>给机器增加更多内存</li>
</ol>
<p>与其他 OOM 错误不同，这是由操作系统而非 JVM 触发的。</p>
<h3 id="8-发生-stack-trace-with-native-method"><a href="#8-发生-stack-trace-with-native-method" class="headerlink" title="8. 发生 stack_trace_with_native_method"></a>8. 发生 stack_trace_with_native_method</h3><h4 id="发生频率-7"><a href="#发生频率-7" class="headerlink" title="发生频率"></a>发生频率</h4><p>1颗星</p>
<h4 id="造成原因-7"><a href="#造成原因-7" class="headerlink" title="造成原因"></a>造成原因</h4><ol>
<li>本机方法（native method）分配失败</li>
<li>打印的堆栈跟踪信息，最顶层的帧是本机方法</li>
</ol>
<h4 id="解决方案-7"><a href="#解决方案-7" class="headerlink" title="解决方案"></a>解决方案</h4><ol>
<li>使用操作系统本地工具进行诊断</li>
</ol>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/%E5%B7%A5%E4%BD%9C/" rel="tag"># 工作</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/blog/2019/02/13/Nginx%E5%A4%84%E7%90%86%E5%9B%BE%E7%89%87%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9/" rel="prev" title="Nginx处理图片注意事项">
                  <i class="fa fa-chevron-left"></i> Nginx处理图片注意事项
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/blog/2019/03/02/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/" rel="next" title="分布式系统">
                  分布式系统 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lliugh</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" rel="noopener" target="_blank">NexT.Gemini</a>
  </div>

    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/blog/js/comments.js"></script><script src="/blog/js/utils.js"></script><script src="/blog/js/motion.js"></script><script src="/blog/js/next-boot.js"></script>

  





  





</body>
</html>
